package com.cloudcross.ssp.loader;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.cloudcross.ssp.model.Operator;

public class OperatorLoader {

    // 在内存中保存查询到的运营商信息
    public List<Operator> OPERTOR_LIST = new ArrayList<Operator>();// 临时存储
    // {key:name,value:id}
    private static Map<String, Long> OPERATOR_MAP = new HashMap<String, Long>();

    private static final OperatorLoader operator = new OperatorLoader();

    private OperatorLoader() {
    }

    public static OperatorLoader getOperator() {
        return operator;
    }

    // {key:name,value:id}
    public Map<String, Long> setOperatorMap() {
        OPERATOR_MAP.clear();
        for (Operator o : OPERTOR_LIST) {
            OPERATOR_MAP.put(o.getCompanyName(), o.getId());
        }
        OPERTOR_LIST = null;
        return OPERATOR_MAP;
    }

    // 根据运营商名称得到ID
    public Long getOperatorIdByNameFromMap(String name) {
        if (StringUtils.isNotBlank(name)) {
            return OPERATOR_MAP.get(name.trim());
        } else {
            return 0l;
        }
    }

}
